﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using CUWo.App.Resources;
using CUWo.Common;

/**
 * 创建时间：2014/11/18 12:48:46
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace CUWo.App.CustomControl
{
    public static class PopupProgressBar
    {
        private static Popup popup;

        static PopupProgressBar()
        {
            popup = new Popup()
            {
                Visibility = System.Windows.Visibility.Visible,
                HorizontalOffset = 0,
                VerticalOffset = 0,
                Height = Application.Current.Host.Content.ActualHeight,
                Width = Application.Current.Host.Content.ActualWidth
            };

            Grid grid = new Grid();
            grid.Height = popup.Height;
            grid.Width = popup.Width;
            grid.Background = new SolidColorBrush(Colors.Black);
            grid.Opacity = 0.9;
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30, GridUnitType.Pixel) });
            grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30, GridUnitType.Pixel) });
            grid.RowDefinitions.Add(new RowDefinition());

            ProgressBar pb = new ProgressBar()
            {
                IsIndeterminate = true,
                Height = 30,
                Width = popup.Width
            };
            TextBlock tb = new TextBlock()
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Text = AppResources.DataLoading,
                Foreground = new SolidColorBrush(Helper.HexToColor(Convert.ToString(Application.Current.Resources["DefaultMessageToastBackgroundColor"]))),
                FontSize = 26
            };
            Grid.SetRow(pb, 1);
            Grid.SetRow(tb, 2);
            grid.Children.Add(pb);
            grid.Children.Add(tb);

            popup.Child = grid;
        }


        public static void OpenProgressBar()
        {
            if (popup != null)
            {
                popup.Visibility = Visibility.Visible;
                popup.IsOpen = true;
            }
        }

        public static void CloseProgressBar()
        {
            if (popup != null)
            {
                popup.IsOpen = false;
                popup.Visibility = Visibility.Collapsed;
            }
        }
    }
}
